const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null,
    shop_item: null,
    count:'',
    pian: 0,
    ding_info: [
      { title: '待成团', imgUrl: 'https://www.58zltc.com/images/order1.png', url: '/pages/mine/order/order', num: 0, typ: 'daituan'},
      { title: '待使用', imgUrl: 'https://www.58zltc.com/images/order2.png', url: '/pages/mine/order/order', num: 0, typ: 'daiyong'},
      { title: '已使用', imgUrl: 'https://www.58zltc.com/images/order3.png', url: '/pages/mine/order/order', num: 0, typ: 'yiyong'},
      { title: '待评价', imgUrl: 'https://www.58zltc.com/images/order4.png', url: '/pages/mine/order/order', num: 0, typ: 'daiping'}
    ],
    setting_info: [
      { title: '领券中心', imgUrl: 'https://www.58zltc.com/images/tool2.png', url: '/pages/shop/coupon/coupon' },
      { title: '分享金', imgUrl: 'https://www.58zltc.com/images/tool3.png', url: '/pages/commission/index' },
      { title: '同城卡', imgUrl: 'https://www.58zltc.com/images/tool4.png', url: '/pages/shop/tccar/tccar' },
      // { title: '我的圈子', imgUrl: 'https://www.58zltc.com/images/tool5.png', url: '/pages/quan/quan/quan' },
      { title: '积分商城', imgUrl: 'https://www.58zltc.com/images/tool5.png', url: '/pages/creditshop/index' },
      { title: '团队分红', imgUrl: 'https://www.58zltc.com/images/tool6.png', url: '/pages/commission/team' },
      { title: '外卖订单', imgUrl: 'https://www.58zltc.com/images/tool7.png', url: '/pages/index/takeout/list/list' },
      { title: '我的预约', imgUrl: 'https://www.58zltc.com/images/tool8.png', url: '/pages/mine/yuyue/list' }
    ],
    products: []
  },
  chat:function(e){
    //同城卡
    app.ihttpGet('https://www.58zltc.com/api.php/Shop/haveTCCard/openid/' + app.globalData.openid, function (res) {
      if (res.data.have_car == 0) {
        wx.showModal({
          title: '提示',
          content: '还没有开通同城卡，是否开通？',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/shop/tccar/tccar',
              })
            } else if (res.cancel) {
              wx.navigateBack({})
            }
          }
        })
        return false;
      }else{
        wx.navigateTo({
          url: '/pages/quan/member/chat',
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (!app.globalData.userInfo) {
      app.getUserInfo();
    }
    this.setData({
      userInfo: app.globalData.userInfo,
    })
    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
    this.setData({
      token: extConfig.appid,
      openid: app.globalData.openid
    })
    var post_data = { openid: app.globalData.openid };
    //骗审
    app.ihttpGet("https://www.58zltc.com/api.php/Index/pian", function (res) {
      if (res.data.pian == 1) {
        that.setData({
          pian: 1
        })
      }
    })
    wx.request({
      url: "https://www.58zltc.com/api.php/Index/mine?token=" + this.data.token,
      method: 'POST',
      data: post_data,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        that.setData({
          info: res.data
        })
        if(res.data.jump ==1){
          wx.showModal({
            title: '提示',
            content: '店铺信息未完善，是否去完善？',
            success: function (res) {
              if (res.confirm) {
                wx.navigateTo({
                  url: '/pages/mine/shop/edit',
                })
              } 
            }
          })
        }
      }
    })
    wx.request({
      url: "https://www.58zltc.com/api.php/Quan/unReadNum?token=" + that.data.token,
      method: 'POST',
      data: post_data,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        that.setData({
          count: res.data
        })
      }
    })
    wx.request({
      url: "https://www.58zltc.com/api.php/Shop/haveShop?token=" + this.data.token,
      method: 'POST',
      data: post_data,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        that.setData({
          shop_item: res.data
        })
      }
    })
    wx.request({
      url: 'https://www.58zltc.com/api.php/Index/getMyfollows?openid=' + app.globalData.openid + '&token=' + that.data.token,
      success: res => {
        that.setData({
          my_follow_num: res.data.length
        })
        wx.hideLoading();
      }
    })
    //获取我的数据
    wx.request({
      url: 'https://www.58zltc.com/api.php/Index/getMyPageInfo?openid=' + app.globalData.openid + '&token=' + that.data.token,
      success: res => {
        var a = that.data.ding_info;
        a[3].num = res.data.witePingNum;
        pageAllInfo: res.data
        that.setData({
          pageAllInfo: res.data,
          ding_info: a,
        })
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  showWitting: function () {
    wx.showToast({
      title: '开发中..敬请期待~',
      icon: 'none',
      duration: 1200
    })
  },
  jumpTccard: function () {
    wx.navigateTo({
      url: '/pages/shop/tccar/index',
    })
  },
  jump: function (e) {
    var type_name = e.currentTarget.dataset.type
    var url = ''
    switch (type_name) {
      case 'ziliao':
        url = '/pages/mine/edit/edit'
        break;
      case 'vipcard':
        url = '/pages/mine/shop/mycard/cardlist'
        break;
      case 'myfabu':
        url = 'info/list'
        break;
      case 'myguanzhu':
        url = 'info/follow'
        break;
      case 'myyouhui':
        url = 'coupon/list'
        break;
      case 'dingdan':
        url = '/pages/mine/order/order'
        break;
      case 'daituan':
        url = '/pages/mine/order/order?tabIndex=0'
        break;
      case 'daiyong':
        url = '/pages/mine/order/order?tabIndex=1'
        break;
      case 'yiyong':
        url = '/pages/mine/order/order?tabIndex=2'
        break;
      case 'daiping':
        url = '/pages/mine/order/order?tabIndex=3'
        break;
    }
    wx.navigateTo({
      url: url,
    })
  },
  jumpc: function (e) {
    var url = e.currentTarget.dataset.url
    app.ihttpGet('https://www.58zltc.com/api.php/ShopAdmin/getInfo/openid/' + app.globalData.openid, function (res) {
      if (res.data.type == 'takeout') {
        wx.navigateTo({
          url: '/pages/mine/shop/waimai',
        })
        return false;
      }else{
        wx.navigateTo({
          url: url,
        })
      }
    })
  },
  jumpcc: function (e) {
    var url = e.currentTarget.dataset.url
    wx.navigateTo({
      url: url,
    })
  },
  intShop: function () {
    wx.navigateTo({
      url: '/pages/creditshop/index',
      //commodity_details
    })
  }
})